home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / biblio / bibtex / utils / refer-tools / tex2refer < prev    next >
Text File  |  1992-07-01  |  5KB  |  152 lines

  1. Article 2347 of comp.text.tex:
  2. Path: ai-lab!snorkelwacker!usc!wuarchive!uunet!mcsun!unido!tub!fauern!fauern!immd2.informatik.uni-erlangen.de!fritzke
  3. From: fritzke@immd2.informatik.uni-erlangen.de (B. Fritzke)
  4. Newsgroups: comp.text.tex
  5. Subject: BIBTEX to REFER conversion program (here it is)
  6. Message-ID: <3065@medusa.informatik.uni-erlangen.de>
  7. Date: 13 Aug 90 11:13:07 GMT
  8. Organization: Universitaet Erlangen, CS-Dep. IMMD II
  9. Lines: 139
  10.  
  11. Recently I posted a request for a program to convert bibliographic 
  12. references in the bibtex format to the refer format.
  13.  
  14. Beneath a lot of 'me too!'-messages I got an answer with an 
  15. awk script, that could do part of the job. After some iterations
  16. of improvement there now exist a pretty good version, that fits
  17. at least my needs.
  18.  
  19. Because many people seem to be interested in the program, I post it
  20. to this newsgroup.
  21.  
  22. How to make it run:
  23.   1. put the stuff after the cut-line in a file called tex2refer (or t2r or so)
  24.   2. Make that file executable by typing
  25.        chmod u+x tex2refer
  26.      on your Unix system
  27.  
  28. Bernd Fritzke
  29.  
  30. Bernd Fritzke ------>  e-mail: fritzke@immd2.informatik.uni-erlangen.de
  31. University of Erlangen, CS IMMD II, Martensstr. 3,  8520 Erlangen (FRG)
  32.  
  33. --------------------------------- cut here -----------------------------------
  34. #! /bin/sh
  35. #
  36. # tex2refer - converts bibtex entries to refer entries
  37. #
  38. # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  39. # This software comes on a 'as is'-basis.
  40. # No guarantee for the correctness is given and no 'service' is provided 
  41. # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  42. #
  43. # This program (an awk skript) converts bibliographic references from the
  44. # bibtex-format to the refer-format.
  45. # it reads from stdin and writes to stdout:
  46. #
  47. # usage: tex2refer < file.bib > file.refer
  48. #
  49. # Be aware, that some information is neccessarily lost, because 
  50. #
  51. #   * several bibtex field names are mapped to the same refer filed name
  52. #      e.g. publisher, organization and school are all mapped to %I
  53. #   * refer doesn't support types for references (like @inproceedings, @article)
  54. #     (therefore the inverse mapping refer2tex is mostly based on heuristics)
  55. #
  56. # In this program are only the more important (I.M.H.O.) field names covered.
  57. # If tex2refer encounters unknown field names, it will ignore them but store their
  58. # names in a list, which is displayed after the conversion process.
  59. #
  60. # With this list the program can easily be extended by adding entries to the 
  61. # associative array 'refer'
  62. #
  63. #
  64. # Thanks to Lee, who provided the main part of the program and added
  65. # some useful comments for readability
  66. #
  67. # Bernd Fritzke (fritzke@immd2.informatik.uni-erlangen.de)
  68. # August 1990
  69. #
  70.  
  71. gawk ' #gnu awk, but works probably also with other versions
  72. BEGIN {
  73.     FS = " "
  74.     refer["author"] = "%A"
  75.     refer["AUTHOR"] = "%A"
  76.     refer["address"] = "%C"
  77.     refer["ADDRESS"] = "%C"
  78.     refer["year"] = "%D"
  79.     refer["YEAR"] = "%D"
  80.     refer["publisher"] = "%I"
  81.     refer["PUBLISHER"] = "%I"
  82.     refer["journal"] = "%J"
  83.     refer["JOURNAL"] = "%J"
  84.     refer["keywords"] = "%K"
  85.     refer["KEYWORDS"] = "%K"
  86.     refer["pages"] = "%P"
  87.     refer["PAGES"] = "%P"
  88.     refer["title"] = "%T"
  89.     refer["TITLE"] = "%T"
  90.     refer["volume"] = "%V"
  91.     refer["VOLUME"] = "%V"
  92.     refer["city"] = "%C"
  93.     refer["CITY"] = "%C"
  94.     refer["booktitle"] = "%B"
  95.     refer["BOOKTITLE"] = "%B"
  96.     refer["note"] = "%o"
  97.     refer["NOTE"] = "%o"
  98.     refer["organization"] = "%I"
  99.     refer["ORGANIZATION"] = "%I"
  100.     refer["school"] = "%I"
  101.     refer["SCHOOL"] = "%I"
  102. }
  103.  
  104. /^@/    {next}   # reference type (not supported by refer) next line
  105. # ---> "next" makes awk goto the start of the awk script & read the next
  106. #    line of input, so here it is making it ignore lines starting
  107. #    with an @ sign.
  108.  
  109. # ensure that an = signs is surrounded by space:
  110. /\=/ { # "=" must be preceeded by `\` , also in line below 
  111.     gsub(/\=/, " & ") # this may cause NF to be updated...
  112.     # Warning -- do not put single quotes in comments!  This does not
  113.     # work reliably in a shell script.
  114. }
  115.  
  116. ($1 in refer && $2 == "=") { # Begin of a bibtex field definition
  117.     gsub(/[{}]/, "")  # deleting curly brackets
  118.     gsub(/,$/, "")    # deleting commas at end of line
  119.     printf "%s ", refer[$1]
  120.     for (i = 3; i <= NF; i++) { # Loop over the keywords ($2 is "=")
  121.     printf " %s", $i        # and print them
  122.     }
  123.     printf "\n" # newline on the end of the refer entry
  124. }
  125.  
  126. (!($1 in refer) && $2 == "=") { #collect unknown keywords
  127.     unknown[$1] = 1
  128.     next
  129. }
  130.  
  131. /[^     ]/ {
  132.     if ($2 != "=") { # This is not a first line of an entry
  133.     # In this case, we are dealing with a continuation line.
  134.     gsub(/[{}]/, "")  # deleting curly braces
  135.     gsub(/,$/, "")    # deleting commas at end of line
  136.     printf "   " 
  137.     for (i = 1; i <= NF; i++) { # Loop over all the keywords 
  138.         printf " %s", $i        # and print them
  139.     }
  140.     printf "\n" # newline on the end of the refer entry
  141.     }
  142. }
  143.  
  144. END {
  145.     for (a in unknown) {
  146.         print "------- unknown keyword:    " a 
  147.     }
  148. }
  149. ' ${@+"$@"}
  150.  
  151.  
  152.